package GUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;

public class GUI extends JFrame {
	public GUI() {
		super("FP Growth Algorithm");

		// file menu
		JMenu fileMenu = new JMenu("File");
		fileMenu.setMnemonic('F');

		// import item
		JMenuItem importItem = new JMenuItem("Import");
		importItem.setMnemonic('I');
		fileMenu.add(importItem);	
		importItem.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// browse file
				JFileChooser chooser = new JFileChooser();
				int choice = chooser.showOpenDialog(GUI.this);
				if(choice == JFileChooser.APPROVE_OPTION) {
					File file = chooser.getSelectedFile();
				}
				
				chooser.setSelectedFile(null);
				
			}
		});

		// exit item
		JMenuItem exitItem = new JMenuItem("Exit");
		exitItem.setMnemonic('x');
		fileMenu.add(exitItem);
		exitItem.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent event) {
				System.exit(0);
			}
		});

		// help item
		JMenu helpMenu = new JMenu("Help");
		helpMenu.setMnemonic('H');

		// about item
		JMenuItem aboutItem = new JMenuItem("About");
		aboutItem.setMnemonic('A');
		helpMenu.add(aboutItem);
		aboutItem.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent event) {
				JOptionPane.showMessageDialog(GUI.this, "hello", "About",
						JOptionPane.PLAIN_MESSAGE);
			}
		});

		// menu bar
		JMenuBar menuBar = new JMenuBar();
		this.setJMenuBar(menuBar);
		menuBar.add(fileMenu);
		menuBar.add(helpMenu);
		// tab
		JTabbedPane tab = new JTabbedPane();
		
		// show tree
		JLabel label1 = new JLabel("FP tree", SwingConstants.CENTER);
		JPanel panel1 = new JPanel();
		panel1.add(label1);
		tab.add("FPTree",panel1);
		
		// show association rule
		JLabel label2 = new JLabel("FP tree", SwingConstants.CENTER);
		JPanel panel2 = new JPanel();
		panel2.add(label2);
		tab.add("Association Rule",panel2);
		
		this.add(tab);
	}
}
